import { Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from "typeorm";
import { EntityModel } from "@midwayjs/orm";
import { MaterialDonate } from "./MaterialDonate.entity";
import { Users } from "./Users.entity";

@EntityModel("material_donate_record", { schema: "heart_neighbor" })
export class MaterialDonateRecord {
  @PrimaryGeneratedColumn({ type: "int", name: "id", comment: "Primary Key" })
  id!: number;    

  @Column("datetime", {
    name: "create_time",
    nullable: true,
    comment: "Create Time",
    default: () => "CURRENT_TIMESTAMP",
  })
  createTime!: Date | null;

  @Column("int", { name: "user_id", nullable: true, comment: "捐赠用户" })
  userId!: number | null;

  @Column("int", { name: "material_donate_id", nullable: true, comment: "物资需求表id" })
  materialDonateId!: number | null;

  @Column("int", { name: "count", nullable: true, comment: "捐赠数量" })
  count!: number | null;

  // 多对一关系：多个捐赠记录对应一个物资捐赠需求
  @ManyToOne(() => MaterialDonate, (materialDonate) => materialDonate.donateRecords, { createForeignKeyConstraints: false })
  @JoinColumn({ name: "material_donate_id" })
  materialDonate!: MaterialDonate;

  // 多对一关系：多个捐赠记录对应一个用户
  @ManyToOne(() => Users, (user) => user.materialDonateRecords, { createForeignKeyConstraints: false })
  @JoinColumn({ name: "user_id" })
  user!: Users;
}
